extends Sprite

signal unit_selected
signal blank_selection

var can_order := false
var unit = null

onready var PU := get_parent().get_node("PlayerUnits")
onready var EU := get_parent().get_node("EnemyUnits")

func _on_Cursor_select(pos):
	position = pos
	visible = true
	if PU and PU.get_unit_at(pos) is Unit:
		modulate = Color(0.4, 0.3, 0.6)
		unit = PU.get_unit_at(pos)
		can_order = true
	elif EU and EU.get_unit_at(pos) is Unit:
		modulate = Color(0.6, 0.3, 0.4)
		unit = EU.get_unit_at(pos)
		can_order = false
	else:
		modulate = Color(1, 1, 1, 1)
		unit = null
		can_order = false
	if unit is Unit:
		emit_signal("unit_selected", unit)
	elif not unit:
		emit_signal("blank_selection")

func _process(delta):
	if unit is Unit:
		position = unit.position
